import { Component, OnInit, ViewChild } from '@angular/core';
import { STColumn, STComponent, STData } from '@delon/abc/st';
import { SFComponent, SFSchema, SFUISchema } from '@delon/form';
import { ModalHelper, _HttpClient } from '@delon/theme';
import { NzModalService } from 'ng-zorro-antd/modal';
import { BussinessStatisticsService } from '../../../business-statistics/services/bussiness-statistics.service';
import { AccountManagemantService } from '../../services/account-managemant.service';
import { PartnerAccountManagementVirtualAccountDetailComponent } from '../virtual-account-detail/virtual-account-detail.component';

@Component({
  selector: 'app-partner-account-management-list',
  templateUrl: './list.component.html',
})
export class PartnerAccountManagementListComponent implements OnInit {
  url = `/user`;
  schema!: SFSchema;
  ui!: SFUISchema;
  @ViewChild('st') private readonly st!: STComponent;
  @ViewChild('sf') private readonly sf!: SFComponent;
  columns: STColumn[] = [];

  constructor(public service: AccountManagemantService, public modal: NzModalService) { }
  /**
   * 查询参数
   */
  get reqParams() {
    const params = { ...this.sf?.value };
    return params
  }

  ngOnInit(): void {
    this.initSF();
    this.initST();
  }

  initSF() {
    this.schema = {
      properties: {
        userName: {
          title: '合伙人名称',
          type: 'string',
          ui: {
            placeholder: '请输入',
          },
        },
        phone: {
          title: '手机号',
          type: 'string',
          ui: {
            placeholder: '请输入',
          },
        },
      }
    }
    this.ui = { '*': { spanLabelFixed: 120, grid: { span: 8, gutter: 12 } }, };
  }
  /**
 * 初始化数据列表
 */
  initST() {
    this.columns = [
      {
        title: '序号',
        className: 'text-center',
        width: '60px',
        format: (item: STData, col: STColumn, idx: number) => {
          return (this.st.pi * this.st.ps) - this.st.ps + idx + 1 + ''
        }
      },
      { title: '合伙人名称', index: 'name', className: 'text-center', width: 250 },
      { title: '手机号', index: 'phone', className: 'text-center', width: 200 },
      {
        title: '账户总额（元）', render: 'allBalance', className: 'text-right',  width: 150,
      },
      // sort: true,
      {
        title: '待入账余额（元）', render: 'unEntryAmount', className: 'text-right', width: 200,
      },
      {
        title: '可用余额（元）', index: 'availableBalance', className: 'text-right', width: 150, type: 'currency'
      },
      { title: '虚拟账户', index: 'virtualAccount', className: 'text-center', width: 220 },
      {
        title: '操作',
        width: 150,
        buttons: [
          {
            text: '虚拟账户明细',
            acl: { ability: ['AM-LIST-viewVirtual'] },
            click: (_record) => this.viewVirtual(_record)
          }
        ]
      }
    ];
  }

  resetSF() {
    this.sf.reset();
    setTimeout(() => {
      this.st.reset();
    })
  }

  /**
   *
   * @param _record 当前行信息
   */
  viewVirtual(_record: any) {
    const modalRef = this.modal.create({
      nzTitle: '虚拟账户明细',
      nzContent: PartnerAccountManagementVirtualAccountDetailComponent,
      nzComponentParams: {
        roleId: _record?.roleId,
      },
      nzWidth: '85%',
      nzFooter: null
    });
    // modalRef.afterClose.subscribe(result => {
    // });
  }

  /**
   *
   */
  export() {

  }

}
